export default class WinUtil {
  static openWin(newUrl, {
    queryParams = null,
    method = 'get'
  } = {}) {
    const iframe = document.createElement('iframe')
    iframe.style.display = 'none'
    const form = document.createElement('form')
    form.action = newUrl
    form.method = method
    form.target = '_self'
    if (queryParams) {
      Object.keys(queryParams).forEach(field => {
        const inputField = document.createElement('input')
        inputField.name = field
        inputField.type = 'hidden'
        inputField.value = queryParams[field]
        form.appendChild(inputField)
      })
    }

    iframe.appendChild(form)
    document.body.appendChild(iframe)
    form.submit()
    setTimeout(() => {
      iframe.parentElement.removeChild(iframe)
    }, 100)
  }
}
